package com.wy.controller;

import com.wy.Service.RoleService;
import com.wy.pojo.Role;
import com.wy.vo.PageVo;
import com.wy.vo.RoleDto;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/role")
@CrossOrigin
public class RoleController {

    @Resource
    private RoleService roleService;
    String msg;
    @GetMapping("/list")
    public List<Role> findAll(){
        return roleService.findAll();
    }

    @GetMapping("/search")
    public PageVo search(Integer current, Integer pageSize, RoleDto dto){
        PageVo pageVo= roleService.searchPage(current,pageSize,dto);
        return pageVo;
    }

    @GetMapping("/add")
    public String add(Role role){
        try{
            roleService.add(role);
            msg="添加成功";
        }catch (Exception e){
            msg="添加失败";
        }
        return msg;
    }

    @GetMapping("/delete")
    public String delete(Integer id){
        try{
            roleService.delete(id);
            msg="删除成功";
        }catch (Exception e){
            msg="删除失败";
        }
        return msg;
    }
    @GetMapping("/update")
    public String update(Role role){
        try{
            roleService.update(role);
            msg="修改成功";
        }catch (Exception e){
            msg="修改失败";
        }
        return msg;
    }


}
